package com.gxgeek.eshopinventory.request;

import com.gxgeek.eshopinventory.entity.ProductInventory;
import com.gxgeek.eshopinventory.service.IProductInventoryService;
import lombok.Data;

/**
 * 请求进来 商品发生交易修改这个商品对应的库存
 * <p>
 * 删除缓存更新数据库
 *
 * @author gaoxing
 * @create 2018-01-12 下午8:37
 */
@Data
public class ProductInventoryDBUpdateRequest implements Request {

    private ProductInventory productInventory;

    IProductInventoryService productInventoryService;

    public ProductInventoryDBUpdateRequest(ProductInventory productInventory, IProductInventoryService productInventoryService) {
        this.productInventory = productInventory;
        this.productInventoryService = productInventoryService;
    }

    @Override
    public void process() {
        //删除redis 中的缓存
        productInventoryService.removeProductInventoryCache(productInventory);
        //修改数据库
        productInventoryService.updateProductInventory(productInventory);
    }

    @Override
    public Integer getProductId() {
        return productInventory.getProductId();
    }


}
